﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;//互动服务
using IWshRuntimeLibrary;
using System.Threading;//线程序的命名空间
using System.Data.SqlClient;
using Excel = Microsoft.Office.Interop.Excel;
using System.Collections;
using System.Net;
using System.Net.Sockets;

//using System.Configuration;
//using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
//using System.Web.UI.HtmlControls;



namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        #region Form1构造函数
        public Form1()
        {
            InitializeComponent();
            str = Application.StartupPath + "\\ConnectString.ini";						//INI文件的物理地址
            strOne = System.IO.Path.GetFileNameWithoutExtension(str); 				//获取INI文件的文件名
            if (System.IO.File.Exists(str)) 											//判断是否存在该INI文件
            {
                comboBox6.Text = ContentReader(strOne, "Data Source", "");				//读取INI文件中服务器节点的内容
                textBox2.Text = ContentReader(strOne, "Data Source1", "");				//读取INI文件中数据库节点的内容
                textBox3.Text = ContentReader(strOne, "Data Source2", "");			    //读取INI文件中用户节点的内容
                textBox7.Text = ContentReader(strOne, "CMIP", "");          			//读取INI文件中密码节点的内容
                dateTimePicker1.Text = ContentReader(strOne, "Start_Date", "");
                comboBox8.Text = ContentReader(strOne, "person1", "");
                comboBox5.Text = ContentReader(strOne, "group", "");
                comboBox9.Text = ContentReader(strOne, "person2", "");
                comboBox4.Text = ContentReader(strOne, "bug_Status", "");
                comboBox7.Text = ContentReader(strOne, "bug_Type", "");
                textBox6.Text = ContentReader(strOne, "directory_File", "");
                textBox11.Text = ContentReader(strOne, "directory_File1", "");
                textBox12.Text = ContentReader(strOne, "directory_File2", "");
                textBox13.Text = ContentReader(strOne, "directory_File3", "");
                textBox14.Text = ContentReader(strOne, "directory_File4", "");
                textBox15.Text = ContentReader(strOne, "directory_File5", "");
                textBox16.Text = ContentReader(strOne, "directory_File6", "");
                textBox17.Text = ContentReader(strOne, "directory_File7", "");
                textBox18.Text = ContentReader(strOne, "directory_File8", "");
                textBox19.Text = ContentReader(strOne, "directory_File9", "");
                textBox20.Text = ContentReader(strOne, "directory_File10", "");
                textBox21.Text = ContentReader(strOne, "directory_File11", "");
                textBox22.Text = ContentReader(strOne, "directory_File12", "");
                textBox23.Text = ContentReader(strOne, "directory_File13", "");
                textBox24.Text = ContentReader(strOne, "directory_File14", "");
                textBox25.Text = ContentReader(strOne, "directory_File15", "");
                toolStripTextBox1.Text = ContentReader(strOne, "DatebaseServer", "");
                toolStripTextBox3.Text = ContentReader(strOne, "Pwd", "");
                textBox30.Text = ContentReader(strOne, "ServerIP", "");
                textBox31.Text = ContentReader(strOne, "ServerPort", "");
                textBox32.Text = ContentReader(strOne, "CM_PWD", "");
                textBox34.Text = ContentReader(strOne, "111_PWD", "");
                textBox35.Text = ContentReader(strOne, "11_PWD", "");
                textBox36.Text = ContentReader(strOne, "HJDZ_PWD", "");
                textBox37.Text = ContentReader(strOne, "ALEX_PWD", "");
                textBox33.Text = ContentReader(strOne, "SEC", "");
                textBox38.Text = ContentReader(strOne, "Site", "");
                textBox39.Text = ContentReader(strOne, "Programm", "");
            }
            this.StartPosition = FormStartPosition.CenterScreen;
            Random r = new Random((int)DateTime.Now.Ticks);
            textBoxUserName.Text = Dns.GetHostName();
            listBoxOnline.HorizontalScrollbar = true;
            
        }

        #endregion

        #region 变量声明区
        string _PWD = "";
        private System.Threading.Thread thdAddFile; //创建一个线程
        private string fn = "";
        FileStream FormerOpen;//实例化FileStream类
        FileStream ToFileOpen;//实例化FileStream类
        public string str = "";//该变量保存INI文件所在的具体物理位置
        public string strOne = "";
        private string dir = "";
        int _SEC = 5000;
        int RE_BUG=0;//记录BUG数
        SqlConnection conn,con;
        Form3 frm3;
        string[] R = new string[100];
        int i = 0;
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpDefault,
            StringBuilder lpReturnedString,
            int nSize,
            string lpFileName);

        public string ContentReader(string area, string key, string def)
        {
            StringBuilder stringBuilder = new StringBuilder(1024); 				//定义一个最大长度为1024的可变字符串
            GetPrivateProfileString(area, key, def, stringBuilder, 1024, str); 			//读取INI文件
            return stringBuilder.ToString();								//返回INI文件的内容
        }

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(
            string mpAppName,
            string mpKeyName,
            string mpDefault,
            string mpFileName);

        class HotKey
        {
            //以下方法用于注册热键 
            [DllImport("user32.dll", SetLastError = true)]
            public static extern bool RegisterHotKey(IntPtr hWnd, int Id, KeyModifiers fsModifiers, Keys vk);
            //以下方法用于注销热键 
            [DllImport("user32.dll", SetLastError = true)]
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
            public enum KeyModifiers
            {
                None = 0,
                Alt = 1,
                Ctrl = 2,
                Shift = 4,
                WindowKey = 8,
            }
        } 

        #endregion

        #region 异步连接Server


                //是否正常退出
        private bool isExit = false;
        private TcpClient client;
        private BinaryReader br;
        private BinaryWriter bw;
       
        //BackgroundWorker connectWork = new BackgroundWorker();
       
        /// <summary>异步方式与服务器进行连接</summary>
        void ConnectToServer()
        {
            client = new TcpClient();
            //此处仅为方便本机调试，实际使用时要将Dns.GetHostName()改为服务器域名
            if(textBox30.Text=="")
            {
                textBox30.Text = "NJ-PUPEI-1";
            }
            if (textBox31.Text == "")
            {
                textBox31.Text = "8090";
            }
            IAsyncResult result = client.BeginConnect(System.Net.Dns.GetHostEntry(textBox30.Text).AddressList[0].ToString(), Convert.ToInt32(textBox31.Text), null, null);
            while (result.IsCompleted == false)
            {
                Thread.Sleep(100);
                AddStatus(".");
            }
            try
            {
                client.EndConnect(result);
                AddStatus("连接成功");
                toolStripStatusLabel1.Text = "成功连接服务器:" + System.Net.Dns.GetHostEntry(textBox30.Text).AddressList[0].ToString() + " " + textBox31.Text;
                //获取网络流
                NetworkStream networkStream = client.GetStream();
                //将网络流作为二进制读写对象
                br = new BinaryReader(networkStream);
                bw = new BinaryWriter(networkStream);
                AsyncSendMessage("Login," + Dns.GetHostName());
                Thread threadReceive = new Thread(new ThreadStart(ReceiveData));
                threadReceive.IsBackground = true;
                threadReceive.Start();
            }
            catch (Exception ex)
            {
                AddStatus("连接失败:" + ex.Message);
                buttonConnect.Enabled = true;
            }
        }

        /// <summary>
        /// 【连接服务器】按钮的Click事件
        /// </summary>
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            buttonConnect.Enabled = false;
            AddStatus("开始连接.");
            ConnectToServer();
        }

        /// <summary>处理接收的服务器端数据</summary>
        private void ReceiveData()
        {
            //object sender=null; EventArgs e=null;
            string receiveString = null;
            while (isExit == false)
            {
                ReceiveMessageDelegate d = new ReceiveMessageDelegate(ReceiveMessage);
                IAsyncResult result = d.BeginInvoke(out receiveString, null, null);
                //使用轮询方式来判断异步操作是否完成
                while (result.IsCompleted == false)
                {
                    if (isExit)
                    {
                        break;
                    }
                    Thread.Sleep(250);
                }
                //获取Begin方法的返回值和所有输入/输出参数
                d.EndInvoke(out receiveString, result);
                if(receiveString==null)
                {
                    if (isExit == false)
                    {
                        MessageBox.Show("与服务器失去联系。");
                    }
                    break;
                }
                string[] splitString = receiveString.Split(',');
                string command = splitString[0].ToLower();
                switch (command)
                {
                    case "login":  //格式：login,用户名
                        AddOnline(splitString[1]);
                        break;
                    case "order":
                        break;
                    case "logout":  //格式：logout,用户名
                        RemoveUserName(splitString[1]);
                        break;
                    case "talk":  //格式：talk,用户名,对话信息
                        AddTalkMessage(splitString[1] + "：\r\n");
                        AddTalkMessage(receiveString.Substring(
                            splitString[0].Length + splitString[1].Length + 2));
                        break;
                    case "dinner":
                        frm3 = new Form3(this);
                        frm3.ShowDialog(this);
                        frm3.TopMost = true;
                        //this.TopMost = true;
                        //if (MessageBox.Show(this,"今天订饭吗？", "订饭", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        //{
                        //    button81_Click(sender, e);
                        //    this.TopMost = false;
                        //}
                        //else
                        //{
                        //    button82_Click(sender, e);
                        //    this.TopMost = false;
                        //}
                        break;
                }
            }
            Application.Exit();
        }
        /// <summary>发送信息状态的数据结构</summary>
        private struct SendMessageStates
        {
            public SendMessageDelegate d;
            public IAsyncResult result;
        }

        /// <summary>异步向服务器端发送数据</summary>
        private void AsyncSendMessage(string message)
        {
            SendMessageDelegate d = new SendMessageDelegate(SendMessage);
            IAsyncResult result = d.BeginInvoke(message, null, null);
            while (result.IsCompleted == false)
            {
                if (isExit)
                {
                    return;
                }
                Thread.Sleep(50);
            }
            SendMessageStates states = new SendMessageStates();
            states.d = d;
            states.result = result;
            Thread t = new Thread(FinishAsyncSendMessage);
            t.IsBackground = true;
            t.Start(states);
        }
        /// <summary>处理接收的服务器端数据</summary>
        private void FinishAsyncSendMessage(object obj)
        {
            SendMessageStates states = (SendMessageStates)obj;
            states.d.EndInvoke(states.result);
        }
        delegate void SendMessageDelegate(string message);
        /// <summary>向服务器端发送数据</summary>
        private void SendMessage(string message)
        {
            try
            {
                bw.Write(message);
                bw.Flush();
            }
            catch
            {
                AddStatus("发送失败!");
            }
        }
        /// <summary>【发送】按钮的Click事件</summary>
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (listBoxOnline.SelectedIndex != -1)
            {
                AsyncSendMessage("Talk," + listBoxOnline.SelectedItem + "," + textBoxSend.Text + "\r\n");
                textBoxSend.Clear();
            }
            else
            {
                MessageBox.Show("请先在[当前在线]中选择一个对话者");
            }
        }

        delegate void ReceiveMessageDelegate(out string receiveMessage);
        /// <summary>读取服务器发过来的信息</summary>
        private void ReceiveMessage(out string receiveMessage)
        {
            receiveMessage = null;
            try
            {
                receiveMessage = br.ReadString();
            }
            catch(Exception ex)
            {
                AddStatus(ex.Message);
            }
        }
        private delegate void AddTalkMessageDelegate(string message);
        /// <summary>向richTextBoxTalkInfo中添加聊天记录</summary>
        private void AddTalkMessage(string message)
        {
            if (richTextBoxTalkInfo.InvokeRequired)
            {
                AddTalkMessageDelegate d = new AddTalkMessageDelegate(AddTalkMessage);
                richTextBoxTalkInfo.Invoke(d, new object[] { message });
            }
            else
            {
                richTextBoxTalkInfo.AppendText(message);
                richTextBoxTalkInfo.ScrollToCaret();
            }
        }
        private delegate void AddStatusDelegate(string message);
        /// <summary>向richTextBoxStatus中添加状态信息</summary>
        private void AddStatus(string message)
        {
            if (richTextBoxStatus.InvokeRequired)
            {
                AddStatusDelegate d = new AddStatusDelegate(AddStatus);
                richTextBoxStatus.Invoke(d, new object[] { message });
            }
            else
            {
                richTextBoxStatus.AppendText(message);
            }
        }
        private delegate void AddOnlineDelegate(string message);
        /// <summary>向listBoxOnline添加在线用户</summary>
        private void AddOnline(string message)
        {
            if (richTextBoxStatus.InvokeRequired)
            {
                AddOnlineDelegate d = new AddOnlineDelegate(AddOnline);
                richTextBoxStatus.Invoke(d, new object[] { message });
            }
            else
            {
                listBoxOnline.Items.Add(message);
                listBoxOnline.SelectedIndex = listBoxOnline.Items.Count - 1;
                listBoxOnline.ClearSelected();
            }
        }
        private delegate void RemoveUserNameDelegate(string userName);
        /// <summary>从listBoxOnline删除离线用户</summary>
        private void RemoveUserName(string userName)
        {
            if (richTextBoxStatus.InvokeRequired)
            {
                RemoveUserNameDelegate d = RemoveUserName;
                richTextBoxStatus.Invoke(d, userName);
            }
            else
            {
                listBoxOnline.Items.Remove(userName);
                listBoxOnline.SelectedIndex = listBoxOnline.Items.Count - 1;
                listBoxOnline.ClearSelected();
            }
        }
        /// <summary>关闭窗口时触发的事件</summary>
        //private void FormClient_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    if (client != null)
        //    {
        //        isExit = true;
        //        if (client.Client.Connected)
        //        {
        //            AsyncSendMessage("Logout," + Dns.GetHostName());
        //            br.Close();
        //            bw.Close();
        //        }
        //        client.Close();
        //    }
        //}


        #endregion
     
        #region 定义文件的复制的方法
        /// </summary>
        /// <param FormerFile="string">源文件路径</param>
        /// <param toFile="string">目的文件路径</param> 
        /// <param SectSize="int">传输大小</param> 
        /// <param progressBar="ProgressBar">ProgressBar控件</param> 
        public void CopyFile(string FormerFile, string toFile, int SectSize, ProgressBar progressBar1)
        {
            progressBar1.Value = 0;//设置进度栏的当前位置为0
            progressBar1.Minimum = 0;//设置进度栏的最小值为0
            FileStream fileToCreate = new FileStream(toFile, FileMode.Create);//创建目的文件，如果已存在将被覆盖
            fileToCreate.Close();//关闭所有资源
            fileToCreate.Dispose();//释放所有资源
            FormerOpen = new FileStream(FormerFile, FileMode.Open, FileAccess.Read);//以只读方式打开源文件
            ToFileOpen = new FileStream(toFile, FileMode.Append, FileAccess.Write);//以写方式打开目的文件
            int max = Convert.ToInt32(Math.Ceiling((double)FormerOpen.Length / (double)SectSize));//根据一次传输的大小，计算传输的个数
            progressBar1.Maximum = max;//设置进度栏的最大值
            int FileSize;//要拷贝的文件的大小
            if (SectSize < FormerOpen.Length)//如果分段拷贝，即每次拷贝内容小于文件总长度
            {
                byte[] buffer = new byte[SectSize];//根据传输的大小，定义一个字节数组
                int copied = 0;//记录传输的大小
                int tem_n = 1;//设置进度栏中进度块的增加个数
                while (copied <= ((int)FormerOpen.Length - SectSize))//拷贝主体部分
                {
                    FileSize = FormerOpen.Read(buffer, 0, SectSize);//从0开始读，每次最大读SectSize
                    FormerOpen.Flush();//清空缓存
                    ToFileOpen.Write(buffer, 0, SectSize);//向目的文件写入字节
                    ToFileOpen.Flush();//清空缓存
                    ToFileOpen.Position = FormerOpen.Position;//使源文件和目的文件流的位置相同
                    copied += FileSize;//记录已拷贝的大小
                    progressBar1.Value = progressBar1.Value + tem_n;//增加进度栏的进度块
                }
                int left = (int)FormerOpen.Length - copied;//获取剩余大小
                FileSize = FormerOpen.Read(buffer, 0, left);//读取剩余的字节
                FormerOpen.Flush();//清空缓存
                ToFileOpen.Write(buffer, 0, left);//写入剩余的部分
                ToFileOpen.Flush();//清空缓存
            }
            else//如果整体拷贝，即每次拷贝内容大于文件总长度
            {
                byte[] buffer = new byte[FormerOpen.Length];//获取文件的大小
                FormerOpen.Read(buffer, 0, (int)FormerOpen.Length);//读取源文件的字节
                FormerOpen.Flush();//清空缓存
                ToFileOpen.Write(buffer, 0, (int)FormerOpen.Length);//写放字节
                ToFileOpen.Flush();//清空缓存
            }
            FormerOpen.Close();//释放所有资源
            ToFileOpen.Close();//释放所有资源
            if (MessageBox.Show("复制完成") == DialogResult.OK)//显示"复制完成"提示对话框
            {
                progressBar1.Value = 0;//设置进度栏的当有位置为0
                
            }
        }

        #endregion

        #region Form1加载

        private void Form1_Load(object sender, EventArgs e)
        {
            frm3 = new Form3(this);
            HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Shift, Keys.F1); //注册Shift+F1
            buttonConnect_Click(sender,e);
            toolStripStatusLabel3.Text = "登录时间：" + DateTime.Now.ToString("yyyy/MM/dd/HH/mm/ss");
            this.notifyIcon1.Visible = true;
            listBoxOnline.Items.Add("全部");
            radioButton13.Enabled = false;
            radioButton14.Enabled = false;
            radioButton15.Enabled = false;
            radioButton16.Enabled = false;
            radioButton14.Checked = false;
            _PWD = textBox34.Text;
           // comboBox1.Text = "Designer Project";
            textBox4.Text = "CM";
            Dir1_Load(sender, e);
           // Dir2_Load(sender, e); 
            this.tabControl1.TabPages.Remove(this.tabPage4);
            this.tabControl1.TabPages.Remove(this.tabPage8);
            //if (!Directory.Exists("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export"))
            //{
            //    Directory.CreateDirectory("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export");
            //}
            if (textBox33.Text != "")
            {
                _SEC = Convert.ToInt32(textBox33.Text) * 1000;
            }
            ReadProduct(comboBoxproduct);
            ReadProduct(comboBoxproduct1);
            ReadProduct(comboBoxproduct2);
            ReadDir();
            if (comboBoxproduct.Items.Count >= 4)
            {
                comboBoxproduct.Text = comboBoxproduct.Items[4].ToString();
            }
            if (comboBoxproduct1.Items.Count >= 4)
            {
                comboBoxproduct1.Text = comboBoxproduct1.Items[4].ToString();
            }
            if (comboBoxproduct2.Items.Count >= 4)
            {
                comboBoxproduct2.Text = comboBoxproduct2.Items[4].ToString();
            }
            button40_Click(sender, e);
            button46_Click(sender, e);
            comboBox1.Text = "Designer Project";
        }

        #endregion

        #region 本地平台区
        private void button3_Click(object sender, EventArgs e)
        {
            if (radioButton9.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\1.1.1", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton10.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\2.0", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton11.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\HJ", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton12.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\ALEX", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton17.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\1.1.1_wait", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton19.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\2.0_wait", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton18.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\HJ_wait", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            if (radioButton20.Checked)
            {
                copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\ALEX_wait", comboBox6.Text);
                MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            }
            
        }
  
        private void button4_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = comboBox6.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                comboBox6.Text = folderBrowserDialog1.SelectedPath;
                string cmd = "c:\\windows\\system32\\inetsrv\\appcmd.exe set app /app.name: " + "\"" + textBox38.Text + "/" + textBox39.Text + "\"" + " /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\WebServer" + "\"";
                //Process.Start(@"c:\windows\system32\inetsrv\appcmd.exe", "set app pupei/WebServer /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\WebServer" + "\"");
                Execute(cmd, 0);
            }
           
            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "Data Source",comboBox6.Text, str); 		//修改INI文件中服务器节点的内容
                //WritePrivateProfileString(strOne, "Data Source1", textBox2.Text, str); 		//修改INI文件中数据库节点的内容
                //WritePrivateProfileString(strOne, "Data Source2", textBox3.Text, str); 			//修改INI文件中用户节点的内容
                //WritePrivateProfileString(strOne, "Pwd", pwd.Text, str); 			//修改INI文件中密码节点的内容
                //MessageBox.Show("恭喜你，修改成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                bool flag = false;
                foreach (object list in comboBox6.Items)
                {
                    if (comboBox6.Text.ToString().Equals(list))
                    {
                        flag = true;
                    }
                }

                if (!flag)
                {
                    comboBox6.Items.Add(comboBox6.Text);
                    WriteTxt(comboBox6.Text);

                }
            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button24_Click(object sender, EventArgs e)
        {
            if (comboBox6.Text == "")
            {
                Process.Start("D:\\");
            }
            else
            {
                Process.Start(comboBox6.Text);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string Arg="";
            if (checkBox1.Checked)
            {
                Arg += "/p ";
            }
            if (checkBox2.Checked)
            {
                Arg += "/r ";
            }
            if (checkBox3.Checked)
            {
                Arg += "/l ";
            }
            if (checkBox4.Checked)
            {
                Arg += "/d";
            }
            if (chk_update_date.Checked)
            {
                Arg += "/u";
            }
            WshShell shell = new WshShell();
            //IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +"\\" + "PuPei’s 平台S端.lnk");
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +"\\" + "PuPei’s 平台S端.lnk");
            shortcut.TargetPath = comboBox6.Text + "\\Server\\Digiwin.Mars.ServerStart.exe";
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application S";
            shortcut.Arguments = Arg;
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp" + "\\" + "PuPei’s 平台S端.lnk");
            Record_MWH("1");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Process.Start(@comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe");
            Thread.Sleep(_SEC);
            login("", _PWD);
            Record_MWH("1");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp"+
     "\\" + "PuPei’s 平台C端.lnk");
            shortcut.TargetPath = comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe";
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application C";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp" +"\\" + "PuPei’s 平台C端.lnk");
            Thread.Sleep(_SEC);
            login("",_PWD);
            Record_MWH("1");
        }

        private void button8_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "PuPei’s 调试C端.lnk");
            shortcut.TargetPath = comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe";
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 调试C";
            shortcut.Arguments = "d /L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp" +"\\" + "PuPei’s 调试C端.lnk");
            Thread.Sleep(_SEC);
            login("", _PWD);
            Record_MWH("1");
        }

        //关闭S和C
        private void button53_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ServerStart")
                {
                    item.Kill();
                }
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    foreach (string s in R)
                    {
                        if (s == null)
                        {
                            break;
                        }
                        string[] sp = s.Split('.');
                        if (sp[1] == "1" && sp[0].Equals(item.Id.ToString()))
                        {
                            item.Kill();
                        }
                    }
                }

            }
        }

        //关闭C
        private void button55_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    foreach (string s in R)
                    {
                        if (s == null)
                        {
                            break;
                        }
                        string[] sp = s.Split('.');
                        if (sp[1] == "1" && sp[0].Equals(item.Id.ToString()))
                        {
                            item.Kill();
                        }
                    }
                }
            }
        }

        private void 清空_Click(object sender, EventArgs e)
        {
            comboBox6.Items.Clear();
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            System.IO.File.Delete(Current+"\\dir.txt");
            System.IO.File.Create(Current + "\\dir.txt");
        }

        private void chk_update_date_CheckedChanged(object sender, EventArgs e)
        {
            if (chk_update_date.Checked)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                checkBox4.Checked = false;
                checkBox1.Enabled = false;
                checkBox2.Enabled = false;
                checkBox3.Enabled = false;
                checkBox4.Enabled = false;
            }
            if (chk_update_date.Checked==false)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                checkBox4.Checked = true;
                checkBox1.Enabled = true;
                checkBox2.Enabled = true;
                checkBox3.Enabled = true;
                checkBox4.Enabled = true;
            }
        }

        #endregion

        #region COPY平台

        private void button11_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openFileDialog1.FileName;
            }
            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                //WritePrivateProfileString(strOne, "Data Source", comboBox6.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "Data Source1", textBox2.Text, str); 		//修改INI文件中服务器1节点的内容
                //WritePrivateProfileString(strOne, "Data Source2", textBox3.Text, str); 			//修改INI文件中服务器2节点的内容
                //WritePrivateProfileString(strOne, "Pwd", pwd.Text, str); 			//修改INI文件中密码节点的内容
                //MessageBox.Show("恭喜你，修改成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                textBox3.Text = openFileDialog2.FileName;
            }
            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                //WritePrivateProfileString(strOne, "Data Source", comboBox6.Text, str); 		//修改INI文件中服务器节点的内容
                //WritePrivateProfileString(strOne, "Data Source1", textBox2.Text, str); 		//修改INI文件中服务器1节点的内容
                WritePrivateProfileString(strOne, "Data Source2", textBox3.Text, str); 			//修改INI文件中服务器2节点的内容
                //WritePrivateProfileString(strOne, "Pwd", pwd.Text, str); 			//修改INI文件中密码节点的内容
                //MessageBox.Show("恭喜你，修改成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Length == 0)
            {
                MessageBox.Show("请选择原文件路径。");
                return;
            }
            fn = textBox2.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            //thdAddFile = new Thread(new ThreadStart(SetAddFile3));//创建一个线程
            //thdAddFile.Start();//执行当前线程
            System.IO.File.Copy(textBox2.Text, "d:\\" + fn.Split('.')[0] + "_E111.RAR");
            MessageBox.Show("复制完毕");
        }

        public delegate void AddFile3();//定义委托

        public void SetAddFile3()
        {
            this.Invoke(new AddFile3(RunAddFile3));//在线程上执行指定的委托
        }

        /// <summary>
        /// 对文件进行复制，并在复制完成后关闭线程
        /// </summary>
        public void RunAddFile3()
        {
            CopyFile(textBox2.Text, "d:\\" + fn, 1024, progressBar1);//复制文件
            thdAddFile.Abort();//关闭线程
        }

        private void button25_Click(object sender, EventArgs e)
        {
            fn = textBox2.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            Process.Start("d:\\" + fn.Split('.')[0] + "_E111.RAR");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (textBox3.Text.Length == 0)
            {
                MessageBox.Show("请选择原文件路径。");
                return;
            }
            fn = textBox3.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            //thdAddFile = new Thread(new ThreadStart(SetAddFile4));//创建一个线程
            //thdAddFile.Start();//执行当前线程
            System.IO.File.Copy(textBox3.Text, "d:\\" + fn.Split('.')[0]+"_E20.RAR");
            MessageBox.Show("复制完毕");
        }

        public void SetAddFile4()
        {
            this.Invoke(new AddFile4(RunAddFile4));//在线程上执行指定的委托
        }
        public delegate void AddFile4();//定义委托
        /// <summary>
        /// 对文件进行复制，并在复制完成后关闭线程
        /// </summary>
        public void RunAddFile4()
        {
            CopyFile(textBox3.Text, "d:\\" + fn, 1024, progressBar1);//复制文件
            thdAddFile.Abort();//关闭线程
        }

        private void button26_Click(object sender, EventArgs e)
        {
            fn = textBox3.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            Process.Start("d:\\" + fn.Split('.')[0] + "_E20.RAR");
        }

        #endregion

        #region 1.1.1 client

        private void button33_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox21.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox21.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 1.1.1UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox34.Text);
            Record_MWH("1");
        }

        private void button17_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox21.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox21.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 1.1.1UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox34.Text);
            Record_MWH("1");
        }

        #endregion

        #region CM client

        private void button81_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox25.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox25.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application UCM";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //    Thread.Sleep(_SEC);
            //    login("", textBox32.Text);
            Record_MWH("0");
        }
        private void button23_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox25.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox25.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application UCM";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //    Thread.Sleep(_SEC);
            //    login("", textBox32.Text);
            Record_MWH("0");
        }
        private void button80_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                        foreach (string s in R)
                        {
                            if (s == null)
                            {
                                break;
                            }
                            string[] sp = s.Split('.');
                            if (sp[1] == "0" && sp[0].Equals(item.Id.ToString()))
                            {
                                item.Kill();
                            }
                        }
                }
            }
        }
        //记录MainWindowHandle
        private void Record_MWH(string s)
        {
            string _s = s;
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    bool b = true;
                    if (R[0]!= null)
                    {
                        foreach (string t in R)
                        {
                            if (t == null)
                            {
                                break;
                            }
                            string[] sp = t.Split('.');
                            if (sp[0].Equals(item.Id.ToString()))
                            {
                                b = false;
                            }
                        }
                        if (b)
                        {
                            R[i] = item.Id.ToString() + "." + _s;
                            i++;
                        }
                    }
                    else
                    {
                        R[i] = item.Id.ToString() + "." + _s;
                        i++;
                    }
                }
            }
        }

        #endregion

        #region 2.0 client
        private void button1_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox22.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox22.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 2.0UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox35.Text);
            Record_MWH("1");
        }

        private void button13_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox22.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox22.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 2.0UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox35.Text);
            Record_MWH("1");
        }

        #endregion

        #region HJ client

        private void button19_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox23.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox23.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application HJ UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox36.Text);
            Record_MWH("1");
        }

        private void button20_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox23.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox23.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application HJ UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox36.Text);
            Record_MWH("1");
        }

        #endregion

        #region ALEX

        private void button14_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox24.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox24.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application ALEX UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox37.Text);
            Record_MWH("1");
        }

        private void button16_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox24.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox24.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application ALEX UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox37.Text);
            Record_MWH("1");
        }

        #endregion

        #region 快捷按钮

        private void button27_Click(object sender, EventArgs e)
        {
            Process.Start(textBox11.Text +"\\TinderDesignerShell.exe");           
        }
       
        private void button28_Click(object sender, EventArgs e)
        {
            Process.Start(textBox13.Text + "\\Ssms.exe"); 
        }

        private void button29_Click(object sender, EventArgs e)
        {
            Process.Start(textBox14.Text + "\\devenv.exe");
        }

        private void button30_Click(object sender, EventArgs e)
        {
            Process.Start(textBox12.Text + "\\SimpleUpdater.exe");
        }

        private void button36_Click(object sender, EventArgs e)
        {
            Process.Start(textBox18.Text + "\\ExtensionToPatch.exe");
        }

        private void button37_Click(object sender, EventArgs e)
        {
            Process.Start(textBox17.Text + "\\Seraphim.KanoMatrix.exe");
        }

        private void button38_Click(object sender, EventArgs e)
        {
            Process.Start(textBox16.Text + "\\Merge.exe");
        }

        private void button39_Click(object sender, EventArgs e)
        {
            Process.Start(textBox15.Text + "\\Reflector.exe");
        }

        private void button56_Click(object sender, EventArgs e)
        {
            Process.Start("C:\\Windows\\system32\\inetsrv\\InetMgr.exe");
        }

        private void button57_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "TinderDesignerShell")
                {
                    item.Kill();
                }
            }
        }

        private void button58_Click(object sender, EventArgs e)
        {
            Process.Start("C:\\Windows\\System32\\iisreset.exe");
        }

        private void button82_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\172.16.1.121\\");
        }

        private void button83_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\172.16.1.29\\");
        }

        private void button84_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\172.16.1.124\\");
        }

        private void button85_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\172.16.1.244\\");
        }

        private void button86_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\172.16.1.45\\");
        }

        private void button87_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\172.16.1.204\\");
        }

        private void button88_Click(object sender, EventArgs e)
        {
            Process.Start("\\\\192.168.9.10\\");
        }

        //国才密码
        private void button60_Click(object sender, EventArgs e)
        {
            Clipboard.SetText("wangguocai71756$");
        }

        #endregion

        #region DLL处理

        private void button54_Click(object sender, EventArgs e)
        {
            string newName;
            //comboBox6.Text = folderBrowserDialog1.SelectedPath;
            //实例化DirectoryInfo对象
            DirectoryInfo dinfo = new DirectoryInfo(textBox6.Text);
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                {

                }
                else
                {
                    if (fsinfo.FullName.Substring(
                fsinfo.FullName.LastIndexOf(".") + 1,
                fsinfo.FullName.Length -
                fsinfo.FullName.LastIndexOf(".") - 1) == "重命名")
                    {
                        System.IO.File.Move(fsinfo.FullName, fsinfo.FullName.Remove(fsinfo.FullName.LastIndexOf(".") + 1));
                        newName = fsinfo.Name.Remove(fsinfo.Name.LastIndexOf(".") + 1);
                        System.IO.File.Copy(fsinfo.FullName.Remove(fsinfo.FullName.LastIndexOf(".") + 1), "C:\\DF_E10_2.0\\WD_PR\\SRC\\Export\\" + newName, true);
                    }
                }
            }
        }

        private void button40_Click(object sender, EventArgs e)
        {
                checkedListBox1.Items.Clear();
               
                    //comboBox6.Text = folderBrowserDialog1.SelectedPath;
                    //实例化DirectoryInfo对象
                DirectoryInfo dinfo=null;
                if (comboBoxproduct.Text == "CM_1.1")
                {
                    if (!Directory.Exists("C:\\DF_CM_1.1\\WD_PR\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_CM_1.1\\WD_PR\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_CM_1.1\\WD_PR\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "DS_1.0")
                {
                    if (!Directory.Exists("C:\\DF_DS_1.0\\WD_PR\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_DS_1.0\\WD_PR\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_DS_1.0\\WD_PR\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_2.0")
                {
                    if (!Directory.Exists("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_1.1.1")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_1.1.1_B")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_ALEX111")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR_C_ALEX\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR_C_ALEX\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR_C_ALEX\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_HJDZ111")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR_C_HJDZ\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR_C_HJDZ\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR_C_HJDZ\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_NBXL111")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR_C_NBXL\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR_C_NBXL\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR_C_NBXL\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_QTDG111")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR_C_QTDG\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR_C_QTDG\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR_C_QTDG\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_TCV111")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR_C_TCV\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR_C_TCV\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR_C_TCV\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_WJBZ111")
                {
                    if (!Directory.Exists("C:\\DF_E10_1.1.1\\WD_PR_C_WJBZ\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_1.1.1\\WD_PR_C_WJBZ\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_1.1.1\\WD_PR_C_WJBZ\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "E10_BAKE20")
                {
                    if (!Directory.Exists("C:\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "SRMS_2.0")
                {
                    if (!Directory.Exists("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export");
                }
                if (comboBoxproduct.Text == "SRMS_BAKE20")
                {
                    if (!Directory.Exists("C:\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export"))
                    {
                        Directory.CreateDirectory("C:\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
                    }
                    dinfo = new DirectoryInfo("C:\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
                }
                //获取指定目录下的所有子目录及文件类型
                FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                FileSystemInfo temp;
                bool flag = true;
                for (int i = fsinfos.Length - 1; i >= 0 && flag; i--)
                {
                    flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
                    for (int j = 0; j < i; j++)
                    {

                        if (fsinfos[j].LastWriteTime < fsinfos[j + 1].LastWriteTime)
                        {

                            flag = true;
                            temp = fsinfos[j];
                            fsinfos[j] = fsinfos[j + 1];
                            fsinfos[j + 1] = temp;
                        }
                    }
                } 
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        //使用获取的文件夹名称实例化DirectoryInfo对象
                        //DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                        //为ListView控件添加文件夹信息
                        //checkedListBox1.Items.Add("abc");
                        //listView1.Items[listView1.Items.Count - 1].SubItems.Add(dirinfo.FullName);
                        //listView1.Items[listView1.Items.Count - 1].SubItems.Add("");
                        //listView1.Items[listView1.Items.Count - 1].SubItems.Add(dirinfo.CreationTime.ToShortDateString());
                    }
                    else 
                    {
                        if (fsinfo.FullName.Substring(
                    fsinfo.FullName.LastIndexOf(".") + 1,
                    fsinfo.FullName.Length -
                    fsinfo.FullName.LastIndexOf(".") - 1) == "dll")
                        {
                            //使用获取的文件名称实例化FileInfo对象
                            FileInfo finfo = new FileInfo(fsinfo.FullName);
                            //为ListView控件添加文件信息
                            checkedListBox1.Items.Add(finfo.Name);
                            //listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.FullName);
                            //listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.Length.ToString());
                            //listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.CreationTime.ToShortDateString());
                        }
                    }
                }
            
        }

        private void button41_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count != 0)
            {
                Process[] ps = Process.GetProcesses();
                foreach (Process item in ps)
                {
                    if (item.ProcessName == "Digiwin.Mars.ServerStart")
                    {
                        item.Kill();
                    }
                }
                
                FileInfo f;
                for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)
                {
                    f = new FileInfo("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export\\"+checkedListBox1.CheckedItems[x].ToString());
                    f.CopyTo(comboBox6.Text + "\\Server\\Programs\\" + checkedListBox1.CheckedItems[x].ToString(), true);
                }
                MessageBox.Show("复制到Server OK");
            }
            
        }

        private void button42_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count != 0)
            {
                // If so, loop through all checked items and print results.

                FileInfo f;
                for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)
                {
                    f = new FileInfo("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export\\" + checkedListBox1.CheckedItems[x].ToString());
                    f.CopyTo(comboBox6.Text + "\\Client\\Programs\\" + checkedListBox1.CheckedItems[x].ToString(), true);
                }
                MessageBox.Show("复制到Client OK");
            }
        }

        private void button52_Click(object sender, EventArgs e)
        {
            Process.Start("C:\\DF_E10_2.0\\WD_PR\\SRC\\Export");
        }

        #endregion

        #region 备份平台文件

        private void Dir_Load(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            
            string Tempdir="",Tempdir1="\\WD";

            if (comboBoxproduct1.Text == "E10_2.0")
            {
                Tempdir = Tempdir + "C:\\DF_E10_2.0";
            }
            if (comboBoxproduct1.Text == "E10_1.1.1")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
            }
            if (comboBoxproduct1.Text == "DS_1.0")
            {
                Tempdir = Tempdir + "C:\\DF_DS_1.0";
            }
            if (comboBoxproduct1.Text == "CM_1.1")
            {
                Tempdir = Tempdir + "C:\\DF_CM_1.1";
            }
            if (comboBoxproduct1.Text == "E10_ALEX111")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
                Tempdir1 = "\\WD_C_ALEX";
            }
            if (comboBoxproduct1.Text == "E10_HJDZ111")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
                Tempdir1 = "\\WD_C_HJDZ";
            }
            if (comboBoxproduct1.Text == "E10_NBXL111")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
                Tempdir1 = "\\WD_C_NBXL";
            }
            if (comboBoxproduct1.Text == "E10_QTDG111")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
                Tempdir1 = "\\WD_C_QTDG";
            }
            if (comboBoxproduct1.Text == "E10_TCV111")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
                Tempdir1 = "\\WD_C_TCV";
            }
            if (comboBoxproduct1.Text == "E10_WJBZ111")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
                Tempdir1 = "\\WD_C_WJBZ";
            }
            if (comboBoxproduct1.Text == "E10_BAKE20")
            {
                Tempdir = Tempdir + "C:\\DF_E10_2.0";
                Tempdir1 = "\\WD_I_BAKE";
            }
            if (comboBoxproduct1.Text == "E10_1.1.1_B")
            {
                Tempdir = Tempdir + "C:\\DF_E10_1.1.1";
            }
            if (comboBoxproduct1.Text == "SRMS_2.0")
            {
                Tempdir = Tempdir + "C:\\DF_E10_2.0";
            }
            if (comboBoxproduct1.Text == "SRMS_BAKE20")
            {
                Tempdir = Tempdir + "C:\\DF_E10_2.0";
                Tempdir1 = "\\WD_I_BAKE";
            }
            try
            {
                if (comboBox1.Text == "Designer Project")
                {
                    DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\businessobjects\\");
                    dir = dinfo.FullName;
                    //获取指定目录下的所有子目录及文件类型
                    FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                    foreach (FileSystemInfo fsinfo in fsinfos)
                    {
                        if (fsinfo is DirectoryInfo)    //判断是否文件夹
                        {
                            //使用获取的文件夹名称实例化DirectoryInfo对象
                            DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                            //为ListView控件添加文件夹信息
                            comboBox2.Items.Add(dirinfo.Name);

                        }

                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(comboBoxproduct1.Text + "没有建立目录");
            }
            if (comboBox1.Text == "Report Project")
            {
                DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\ReportObjects\\");
                dir = dinfo.FullName;
                //获取指定目录下的所有子目录及文件类型
                FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        //使用获取的文件夹名称实例化DirectoryInfo对象
                        DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                        //为ListView控件添加文件夹信息
                        comboBox2.Items.Add(dirinfo.Name);

                    }

                }
            }
            if (comboBox1.Text == "Batch Project")
            {
                DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\BatchObjects\\");
                dir = dinfo.FullName;
                //获取指定目录下的所有子目录及文件类型
                FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        //使用获取的文件夹名称实例化DirectoryInfo对象
                        DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                        //为ListView控件添加文件夹信息
                        comboBox2.Items.Add(dirinfo.Name);

                    }

                }
            }
            if (comboBox1.Text == "DataModel Project")
            {
                DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\DataModels\\");
                dir = dinfo.FullName;
                //获取指定目录下的所有子目录及文件类型
                FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        //使用获取的文件夹名称实例化DirectoryInfo对象
                        DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                        //为ListView控件添加文件夹信息
                        comboBox2.Items.Add(dirinfo.Name);

                    }

                }
            }
            if (comboBox1.Text == "ValidatorSnippet Project") 
            {
                return;
            }
            if (comboBox2.Items.Count > 0)
            {
                comboBox2.Text = comboBox2.Items[0].ToString();
            }
            else
            {
                comboBox2.Text = "";
            }
        }

        private void button49_Click(object sender, EventArgs e)
        {
            Process.Start(dir);
        }

        private void button43_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否删除" + comboBox2.Text, "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
            {
                DirectoryInfo d = new DirectoryInfo(dir + comboBox2.Text);
                d.Delete(true);
                MessageBox.Show("ok!!!");
            }

        }

        private void button44_Click(object sender, EventArgs e)
        {
            Process.Start(textBox19.Text);
        }

        private void button45_Click(object sender, EventArgs e)
        {
            string Tempdir="";

            if (comboBoxproduct1.Text == "E10_2.0")
            {
                Tempdir = "\\2.0";
            }
            if (comboBoxproduct1.Text == "E10_1.1.1")
            {
                Tempdir = "\\1.1.1";
            }
            if (comboBoxproduct1.Text == "DS_1.0")
            {
                Tempdir = "\\DS_1.0";
            }
            if (comboBoxproduct1.Text == "CM_1.1")
            {
                Tempdir = "\\CM_1.1";
            }
            if (comboBoxproduct1.Text == "E10_ALEX111")
            {
                Tempdir = "\\1.1.1ALEX";
            }
            if (comboBoxproduct1.Text == "E10_HJDZ111")
            {
                Tempdir = "\\1.1.1HJDZ";
            }
            if (comboBoxproduct1.Text == "E10_NBXL111")
            {
                Tempdir = "\\1.1.1NBXL";
            }
            if (comboBoxproduct1.Text == "E10_QTDG111")
            {
                Tempdir = "\\1.1.1QTDG";
            }
            if (comboBoxproduct1.Text == "E10_TCV111")
            {
                Tempdir = "\\1.1.1TCV";
            }
            if (comboBoxproduct1.Text == "E10_WJBZ111")
            {
                Tempdir = "\\1.1.1WJBZ";
            }
            if (comboBoxproduct1.Text == "E10_BAKE20")
            {
                Tempdir = "\\2.0BAKE";
            }
            if (comboBoxproduct1.Text == "E10_1.1.1_B")
            {
                Tempdir = "\\1.1.1B";
            }
            if (comboBoxproduct1.Text == "SRMS_2.0")
            {
                Tempdir = "\\2.0SRMS"; 
            }
            if (comboBoxproduct1.Text == "SRMS_BAKE20")
            {
                Tempdir = "\\2.0SRMS_BAKE"; 
            }

            copyDirectory(dir + comboBox2.Text, textBox19.Text + "\\" + comboBox2.Text + Tempdir + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "—" + DateTime.Now.ToString("HH-mm-ss") + "—" + textBox29.Text);
            MessageBox.Show("备份" + comboBox2.Text + "成功");
        }

        #endregion

        #region 菜单控制
        //菜单控制
        private void Invisible_Tab(object sender, EventArgs e)
        {
            this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab);

        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage1"))
            {
                this.tabControl1.TabPages.Add(this.tabPage1);
                this.tabControl1.SelectedTab = tabPage1;
            }
            this.tabControl1.SelectedTab = tabPage1;
        }

        private void menuItem5_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage2"))
            {
                this.tabControl1.TabPages.Add(this.tabPage2);
                this.tabControl1.SelectedTab = tabPage2;
            }
            this.tabControl1.SelectedTab = tabPage2;
        }

        private void menuItem6_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage3"))
            {
                this.tabControl1.TabPages.Add(this.tabPage3);
                this.tabControl1.SelectedTab = tabPage3;
            }
            this.tabControl1.SelectedTab = tabPage3;
        }

        private void menuItem8_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage4"))
            {
                this.tabControl1.TabPages.Add(this.tabPage4);
                this.tabControl1.SelectedTab = tabPage4;
            }
            this.tabControl1.SelectedTab = tabPage4;
        }

        private void menuItem7_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage5"))
            {
                this.tabControl1.TabPages.Add(this.tabPage5);
                this.tabControl1.SelectedTab = tabPage5;
            }
            this.tabControl1.SelectedTab = tabPage5;
        }
        private void menuItem12_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage8"))
            {
                this.tabControl1.TabPages.Add(this.tabPage8);
                this.tabControl1.SelectedTab = tabPage8;
            }
            this.tabControl1.SelectedTab = tabPage8;
        }

        private void menuItem9_Click(object sender, EventArgs e)
        {
            if (client != null)
            {
                
                if (client.Client.Connected)
                {
                    AsyncSendMessage("Logout," + textBoxUserName.Text);
                    br.Close();
                    bw.Close();
                }
                isExit = true;
                client.Close();
            }
            
            Application.Exit();
        }
        private void menuItem10_Click(object sender, EventArgs e)
        {
            Process.Start(System.Environment.CurrentDirectory + "\\help.chm");
        }

        #endregion

        #region CM

        private void button46_Click(object sender, EventArgs e)
        { 
            if (textBox4.Text == "")//判断是否输入数据库名称
            {
                MessageBox.Show("请输入要连接的数据库名称");//弹出提示信息
            }
            else
            {
                try//调用try…catch语句
                {
                    //声明一个字符串用于存储连接数据库字符串
                    string ConStr = "server=" + textBox7.Text + ";database=" + textBox4.Text.Trim() + ";uid=CM;pwd=111111";
                    //创建一个SqlConnection对象
                    conn = new SqlConnection(ConStr);
                    conn.Open();//打开连接
                    if (conn.State == ConnectionState.Open)//判断当前连接的状态
                    {
                        //显示状态信息
                        label3.Text = "数据库【" + textBox4.Text.Trim() + "】已经连接并打开";
                        timer1.Enabled = true;
                        SqlCommand cmd = new SqlCommand();	//创建一个SqlCommand对象
                        cmd.Connection = conn;				//设置Connection属性
                        //设置CommandText属性，设置SQL语句
                        cmd.CommandText = "select PRODUCT_GROUP_CODE FROM PRODUCT_GROUP WHERE ApproveStatus='Y' ORDER BY PRODUCT_GROUP_CODE";
                        //设置CommandType属性为Text，使其只执行SQL语句文本形式
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sdr = cmd.ExecuteReader();
                        while (sdr.Read())
                        {
                                WriteProduct(sdr["PRODUCT_GROUP_CODE"].ToString());
                        }
                        sdr.Close();
                        ReadProduct(comboBoxproduct);
                    }
                }
                catch
                {
                    MessageBox.Show("连接数据库失败");//出现异常弹出提示
                }
            }
        }

        private void button47_Click(object sender, EventArgs e)
        {
            conn.Close();
            timer1.Enabled = false;
            label3.Text = "数据库【" + textBox4.Text.Trim() + "】已经断开";
        }

        private void button48_Click(object sender, EventArgs e)
        {
            try
            {
                //判断是否打开连接或者文本框不为空
                if (conn.State == ConnectionState.Open)
                {
                    SqlCommand cmd = new SqlCommand();	//创建一个SqlCommand对象
                    cmd.Connection = conn;				//设置Connection属性
                    //设置CommandText属性，设置SQL语句
                    cmd.CommandText = "select count(*) from ISSUE WHERE EMPLOYEE_ID in (select EMPLOYEE_ID from EMPLOYEE where EMPLOYEE_NAME='" + comboBox8.Text + "') and STATUS='0'";
                    //设置CommandType属性为Text，使其只执行SQL语句文本形式
                    cmd.CommandType = CommandType.Text;
                    //使用ExecuteScalar方法获取指定数据表中的数据数量
                    int i = Convert.ToInt32(cmd.ExecuteScalar());
                    textBox5.Text = i.ToString();
                    //MessageBox.Show("目前有" + textBox5.Text+"个新BUG！");
                }
                else
                {
                    button47_Click(sender, e);
                    button46_Click(sender, e);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("网络已断，请检查网络连接并重新连接！");
            }
        }

        private void TextChange(object sender, EventArgs e)
        {

            if (textBox5.Text != "" && textBox5.Text != "0" && Convert.ToInt32(textBox5.Text)>RE_BUG)
            {
                this.TopMost = true;
                if (MessageBox.Show("你共有" + textBox5.Text + "未派工BUG！刚刚新来了" + (Convert.ToInt32(textBox5.Text) - RE_BUG) + "条BUG", "BUG", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.TopMost = false;
                }
                else 
                {
                    this.TopMost = false;
                }
                RE_BUG = Convert.ToInt32(textBox5.Text);
            }
            if (Convert.ToInt32(textBox5.Text) < RE_BUG)
            {
                RE_BUG = Convert.ToInt32(textBox5.Text);
            }
        }
        //变化日期储存ini文件
        private void change_Date(object sender, EventArgs e)
        {

            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "Start_Date", dateTimePicker1.Value.ToString(), str); 		//修改INI文件中服务器节点的内容
               
            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void change_Com_Box8(object sender, EventArgs e)
        {
            
            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "person1", comboBox8.Text, str); 		//修改INI文件中服务器节点的内容

            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void change_Group(object sender, EventArgs e)
        {

            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "group", comboBox5.Text, str); 		//修改INI文件中服务器节点的内容

            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void change_Com_Box9(object sender, EventArgs e)
        {

            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "person2", comboBox9.Text, str); 		//修改INI文件中服务器节点的内容

            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void change_Com_Box4(object sender, EventArgs e)
        {

            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "bug_Status", comboBox4.Text, str); 		//修改INI文件中服务器节点的内容

            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void change_Com_Box7(object sender, EventArgs e)
        {

            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "bug_Type", comboBox7.Text, str); 		//修改INI文件中服务器节点的内容

            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button50_Click(object sender, EventArgs e)
        {
            try
            {
                string Bug;
                string bugStutas;
                string person;
                string unit;
                if (comboBox4.Text == "外部BUG")
                {
                    Bug = "1";
                }
                else if (comboBox4.Text == "内部BUG")
                {
                    Bug = "2";
                }
                else
                {
                    Bug = "1' or ISSUE.RESPONSE_TYPE = '" + "2";
                }

                if (comboBox7.Text == "未结")
                {
                    bugStutas = "STATUS NOT IN('5','6','7','9')";
                }
                else if (comboBox7.Text == "已结")
                {
                    bugStutas = "STATUS IN('5','6','7','9')";
                }
                else
                {
                    bugStutas = "1=1";
                }

                if (comboBox9.Text == "全部")
                {
                    person = "1=1";
                }
                else
                {
                    person = "EMPLOYEE_NAME='" + comboBox9.Text + "'";
                }

                if (comboBox5.Text == "全部")
                {
                    unit = "1=1";
                }
                else
                {
                    unit = "ADMIN_UNIT.ADMIN_UNIT_NAME ='" + comboBox5.Text + "'";

                }
                string sql = "select WCG.*,ISSUE.ISSUE_DESCRIPTION BUG描述,( DateDiff ( day, WCG.创建日期 , WCG.结案日期 ) - DateDiff( week , WCG.创建日期 , WCG.结案日期 ) * 2 ";
                sql += " + case   when   datepart(dw, WCG.创建日期)   between   2   and   7   then   1   else   0   end ";
                sql += " - case   when   datepart(dw, WCG.结案日期) = 7   then   1   else   0   end ";
                sql += " + case   when   DATEPART(DW,WCG.创建日期) in (7,1) and DATEPART(DW,WCG.结案日期) in (7,1) then 1 else 0 end ) as 所用天数 ";
                sql += "from (SELECT ADMIN_UNIT_NAME AS '部门',EMPLOYEE_NAME 姓名,ISSUE.DOC_NO BUG单号,CAST(ISSUE.CreateDate AS date) 创建日期,CAST(PROCESS_DATE AS date) 结案日期,case when PROCESS_DATE is null then '未结' else '已结' end 是否结案,case when RESPONSE_TYPE = '1' then '外部Bug' else '内部Bug' end BUG类型,MODULE.MODULE_CODE 模块 FROM ISSUE LEFT JOIN ISSUE_D ON ISSUE.ISSUE_ID=ISSUE_D.ISSUE_ID and (ISSUE_D.PROCESS_TYPE='5'or ISSUE_D.PROCESS_TYPE='2'or ISSUE_D.PROCESS_TYPE='4') LEFT JOIN EMPLOYEE ON ISSUE.EMPLOYEE_ID=EMPLOYEE.EMPLOYEE_ID LEFT JOIN EMPLOYEE_D ON EMPLOYEE.EMPLOYEE_ID=EMPLOYEE_D.EMPLOYEE_ID LEFT JOIN ADMIN_UNIT ON ADMIN_UNIT.ADMIN_UNIT_ID=EMPLOYEE_D.ADMIN_UNIT_ID left Join MODULE on ISSUE.MODULE_ID=MODULE.MODULE_ID WHERE ISSUE.CATEGORY='1'AND " + bugStutas + " AND " + person + " and " + unit + "and (ISSUE.RESPONSE_TYPE='" + Bug + "')) AS WCG ";
                sql += "left Join ISSUE ";
                sql += "on WCG.BUG单号=ISSUE.DOC_NO ";
                sql += "where (CAST(WCG.结案日期 AS date)>='" + dateTimePicker1.Value.ToShortDateString() + "' ";
                sql += "and CAST(WCG.结案日期 AS date)<='" + dateTimePicker2.Value.ToShortDateString() + "') ";
                sql += "or CAST(WCG.结案日期 AS date) is null ";
                string sql0 = "select count(*) from (" + sql + ") as JS";
                string sql1 = "select count(*) from (" + sql + ") as JS where JS.所用天数 is not null ";
                string sql2 = "select count(*) from (" + sql + ") as JS where JS.所用天数 <=3 ";
                string sql3 = "select count(*) from (" + sql + ") as JS where JS.所用天数 >3 ";

                //创建一个SqlCommand对象
                SqlCommand cmd = new SqlCommand(sql0, conn);
                int i = Convert.ToInt32(cmd.ExecuteScalar());
                textBox1.Text = i.ToString();

                cmd = new SqlCommand(sql1, conn);
                int i2 = Convert.ToInt32(cmd.ExecuteScalar());
                textBox10.Text = i2.ToString();

                cmd = new SqlCommand(sql2, conn);
                decimal i3 = Convert.ToInt32(cmd.ExecuteScalar());

                cmd = new SqlCommand(sql3, conn);
                decimal i4 = Convert.ToInt32(cmd.ExecuteScalar());

                if (i == 0 || i2 == 0)
                {
                    textBox8.Text = "0%";
                    textBox8.BackColor = Color.White;
                    textBox9.Text = "0%";
                }
                else if (i3 == 0 && i4 != 0)
                {
                    textBox8.Text = "0%";
                    textBox8.BackColor = Color.Red;
                    textBox9.Text = "100%";
                }
                else if (i4 == 0 && i3 != 0)
                {
                    textBox8.Text = "100%";
                    textBox8.BackColor = Color.Green;
                    textBox9.Text = "0%";
                }
                else
                {
                    //textBox8.Text = (i3).ToString();
                    //textBox9.Text = (i4).ToString();
                    textBox8.Text = Convert.ToString(Math.Round((i3 / i2) * 100, 2)) + "%";
                    textBox9.Text = Convert.ToString(Math.Round((i4 / i2) * 100, 2)) + "%";

                    if (((i3 / i2) * 100) < 87)
                    {
                        textBox8.BackColor = Color.Red;
                    }
                    else
                    {
                        textBox8.BackColor = Color.Green;
                    }
                }


                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);//创建一个SqlDataAdapter对象
                // sda.SelectCommand = cmd;				//设置SqlDataAdapter对象的SelectCommand属性为cmd
                DataSet ds = new DataSet();				//创建一个DataSet对象
                sda.Fill(ds);				//使用SqlDataAdapter对象的Fill方法填充DataSet数据集;
                dataGridView1.DataSource = ds.Tables[0];//设置dataGridView1控件的数据源
            }
            catch (Exception ex)
            {
                MessageBox.Show("网络已断，请检查网络连接并重新连接！");
            }

        }

        private Excel.Application G_ea;//定义Word应用程序字段
        private object G_missing = //定义G_missing字段并添加引用
            System.Reflection.Missing.Value;
       
        private void button51_Click(object sender, EventArgs e)
        {
            List<Bug> P_Fruit = new List<Bug>();//创建数据集合
            foreach (DataGridViewRow dgvr in dataGridView1.Rows)
            {
                if (dgvr.Cells[0].Value == null)
                {
                    continue;
                }
                P_Fruit.Add(new Bug()//向数据集合添加数据
                {
                    Dep = dgvr.Cells[0].Value.ToString(),
                    Name = dgvr.Cells[1].Value.ToString(),
                    Doc_No = dgvr.Cells[2].Value.ToString(),
                    Date_Create = dgvr.Cells[3].Value.ToString(),
                    Date_Over = dgvr.Cells[4].Value.ToString(),
                    Is = dgvr.Cells[5].Value.ToString(),
                    Type = dgvr.Cells[6].Value.ToString(),
                    Model = dgvr.Cells[7].Value.ToString(),
                    Cla = dgvr.Cells[8].Value.ToString()
                   
                });
            }
            SaveFileDialog P_SaveFileDialog =//创建保存文件对话框对象
                new SaveFileDialog();
            P_SaveFileDialog.Filter = "*.xls|*.xlsx";
            if (DialogResult.OK ==//确认是否保存文件
                P_SaveFileDialog.ShowDialog())
            {
                ThreadPool.QueueUserWorkItem(//开始线程池
                (pp) =>//使用lambda表达式
                {
                    G_ea = new Microsoft.Office.Interop.Excel.Application();//创建应用程序对象
                    Excel.Workbook P_wk = G_ea.Workbooks.Add(G_missing);//创建Excel文档
                    Excel.Worksheet P_ws = (Excel.Worksheet)P_wk.Worksheets.Add(//创建工作区域
                        G_missing, G_missing, G_missing, G_missing);
                    for (int i = 0; i < P_Fruit.Count; i++)
                    {
                        P_ws.Cells[i + 1, 1] = P_Fruit[i].Dep;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 2] = P_Fruit[i].Name;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 3] = P_Fruit[i].Doc_No;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 4] = P_Fruit[i].Date_Create;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 5] = P_Fruit[i].Date_Over;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 6] = P_Fruit[i].Is;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 7] = P_Fruit[i].Type;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 8] = P_Fruit[i].Model;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 9] = P_Fruit[i].Cla;//向Excel文档中写入内容
                    }
                    P_wk.SaveAs(//保存Word文件
                        P_SaveFileDialog.FileName, G_missing, G_missing, G_missing,
                        G_missing, G_missing, Excel.XlSaveAsAccessMode.xlShared, G_missing,
                        G_missing, G_missing, G_missing, G_missing);
                    ((Excel._Application)G_ea.Application).Quit();//退出应用程序

                    this.Invoke(//调用窗体线程
                        (MethodInvoker)(() =>//使用lambda表达式
                        {
                            MessageBox.Show(//弹出消息对话框
                                "成功创建Excel文档！", "提示！");
                        }));
                });
            }
        }

        #endregion

        #region PickList&BusinessType

        private void Dir1_Load(object sender, EventArgs e)
        {
            comboBox3.Items.Clear();
            DirectoryInfo dinfo=null;
           
            if (radioButton1.Checked)
            {
                dinfo = new DirectoryInfo("C:\\DF_E10_2.0\\WD\\GlobalResources\\PickList\\");
                
            }
            if (radioButton2.Checked)
            {
                dinfo = new DirectoryInfo("C:\\DF_E10_2.0\\WD\\GlobalResources\\BusinessType\\");
                
            }
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                {
                    //使用获取的文件夹名称实例化DirectoryInfo对象
                    //DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                    //为ListView控件添加文件夹信息
                    //comboBox2.Items.Add(dirinfo.Name);

                }
                else 
                {
                    //使用获取的文件夹名称实例化FileInfo对象
                    FileInfo dirinfo = new FileInfo(fsinfo.FullName);
                    //为ListView控件添加文件夹信息
                    comboBox3.Items.Add(dirinfo.Name.Substring(13));

                }

            }
            comboBox3.Text = comboBox3.Items[0].ToString();
            
        }
        private void displayText(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            StreamReader SReader=null;
            if (radioButton1.Checked)
            {
                
                SReader = new StreamReader("C:\\DF_E10_2.0\\WD\\GlobalResources\\PickList\\PickListType." + comboBox3.Text, Encoding.UTF8);
            }
            if (radioButton2.Checked)
            {
                
                SReader = new StreamReader("C:\\DF_E10_2.0\\WD\\GlobalResources\\BusinessType\\BusinessType." + comboBox3.Text, Encoding.UTF8);
            }
            string strLine = string.Empty;
            while ((strLine = SReader.ReadLine()) != null)
            {
                richTextBox1.Text += strLine + Environment.NewLine;
            }
        }

        #endregion

        #region 递归拷贝所有子目录方法

        /// <summary>
        /// 递归拷贝所有子目录。
        /// </summary>
        /// <param >源目录</param>
        /// <param >目的目录</param>
        private void copyDirectory(string sPath, string dPath)
        {
            string[] directories = System.IO.Directory.GetDirectories(sPath);
            if (!System.IO.Directory.Exists(dPath))
                System.IO.Directory.CreateDirectory(dPath);
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(sPath);
            System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
            CopyAllFile(dir, dPath);
            if (dirs.Length > 0)
            {
                foreach (System.IO.DirectoryInfo temDirectoryInfo in dirs)
                {
                    string sourceDirectoryFullName = temDirectoryInfo.FullName;
                    string destDirectoryFullName = sourceDirectoryFullName.Replace(sPath, dPath);
                    if (!System.IO.Directory.Exists(destDirectoryFullName))
                    {
                        System.IO.Directory.CreateDirectory(destDirectoryFullName);
                    }
                    CopyAllFile(temDirectoryInfo, destDirectoryFullName);
                    copyDirectory(sourceDirectoryFullName, destDirectoryFullName);
                }
            }

        }

        /// <summary>
        /// 拷贝目录下的所有文件到目的目录。
        /// </summary>
        /// <param >源路径</param>
        /// <param >目的路径</param>
        private void CopyAllFile(System.IO.DirectoryInfo path, string desPath)
        {
            string sourcePath = path.FullName;
            System.IO.FileInfo[] files = path.GetFiles();
            foreach (System.IO.FileInfo file in files)
            {
                string sourceFileFullName = file.FullName;
                string destFileFullName = sourceFileFullName.Replace(sourcePath, desPath);
                if (file.Attributes.ToString().IndexOf("ReadOnly") != -1)
                {
                    file.Attributes = FileAttributes.Normal;
                }
                file.CopyTo(destFileFullName, true);
            }
        }

        #endregion      

        #region 提取平台文件
        private void button59_Click(object sender, EventArgs e)
        {
            string tempDir = "\\Client", tempDir1 = "\\Server",tempDir2="";
            if (comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
                comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
                comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
                comboBoxproduct1.Text != "SRMS_BAKE20")
            {
                tempDir = "\\Client\\Customization";
                tempDir1 = "\\Server\\Customization";
                tempDir2 = "\\Customization";
                Directory.CreateDirectory(textBox6.Text + "\\平台文件");
                Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir + "\\Programs\\");
                Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir1 + "\\Programs\\");
            }
            else
            {
                Directory.CreateDirectory(textBox6.Text + "\\平台文件");
                Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir + "\\Programs\\");
                Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir1 + "\\Programs\\");
            }
            DirectoryInfo dinfo = new DirectoryInfo(comboBox6.Text + tempDir1 + "\\Programs");
            FileSystemInfo[] fsinfos;
            FileSystemInfo temp;
            bool flag;
            if (Directory.Exists(dinfo.ToString()))
            {
                //获取指定目录下的所有子目录及文件类型
                fsinfos = dinfo.GetFileSystemInfos();
                flag = true;
                for (int i = fsinfos.Length - 1; i >= 0 && flag; i--)
                {
                    flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
                    for (int j = 0; j < i; j++)
                    {

                        if (fsinfos[j].LastWriteTime < fsinfos[j + 1].LastWriteTime)
                        {

                            flag = true;
                            temp = fsinfos[j];
                            fsinfos[j] = fsinfos[j + 1];
                            fsinfos[j + 1] = temp;
                        }
                    }
                }
                foreach (FileSystemInfo fsinfo in fsinfos)
                {

                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {

                    }
                    else
                    {
                        string[] sp = fsinfo.Name.Split('.');
                        if (sp[0].Equals("Digiwin"))
                        {
                            if ((sp[2].Length == comboBox2.Text.Length) && fsinfo.Name.Substring(12, comboBox2.Text.Length).Equals(comboBox2.Text))
                            {
                                System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件" + tempDir1 + "\\Programs\\" + fsinfo.Name, true);
                            }
                            if ((comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
                comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
                comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
                comboBoxproduct1.Text != "SRMS_BAKE20") && (sp[2].Length) - 2 == comboBox2.Text.Length && fsinfo.Name.Substring(14, comboBox2.Text.Length).Equals(comboBox2.Text))
                            {
                                System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件" + tempDir1 + "\\Programs\\" + fsinfo.Name, true);
                            }

                        }
                    }

                }
            }
            dinfo = new DirectoryInfo(comboBox6.Text + tempDir + "\\Programs");
            if (Directory.Exists(dinfo.ToString()))
            {
                //获取指定目录下的所有子目录及文件类型
                fsinfos = dinfo.GetFileSystemInfos();
                flag = true;
                for (int i = fsinfos.Length - 1; i >= 0 && flag; i--)
                {
                    flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
                    for (int j = 0; j < i; j++)
                    {

                        if (fsinfos[j].LastWriteTime < fsinfos[j + 1].LastWriteTime)
                        {

                            flag = true;
                            temp = fsinfos[j];
                            fsinfos[j] = fsinfos[j + 1];
                            fsinfos[j + 1] = temp;
                        }
                    }
                }
                foreach (FileSystemInfo fsinfo in fsinfos)
                {

                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {

                    }
                    else
                    {
                        string[] sp = fsinfo.Name.Split('.');
                        if (sp[0].Equals("Digiwin"))
                        {

                            if (fsinfo.Name.Substring(12, sp[2].Length).Equals(comboBox2.Text))
                            {
                                System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件" + tempDir + "\\Programs\\" + fsinfo.Name, true);
                            }
                            if ((comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
                comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
                comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
                comboBoxproduct1.Text != "SRMS_BAKE20") && fsinfo.Name.Substring(14, sp[2].Length).Equals(comboBox2.Text))
                            {
                                System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件" + tempDir + "\\Programs\\" + fsinfo.Name, true);
                            }
                        }
                    }

                }
            }

            if (comboBox1.Text == "Designer Project")
            {
                copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件" + tempDir + "\\BusinessObjects\\" + comboBox2.Text);
                copyDirectory(comboBox6.Text + tempDir1 + "\\BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件" + tempDir1 + "\\BusinessObjects\\" + comboBox2.Text);
                copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件" + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement");

                MessageBox.Show("提取" + comboBox2.Text + "成功");
            }
            if (comboBox1.Text == "Report Project")
            {
                copyDirectory(comboBox6.Text + tempDir1 + "\\ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件" + tempDir1 + "\\ReportObjects\\" + comboBox2.Text);
                copyDirectory(comboBox6.Text + "\\Webserver\\bin" + tempDir2 + "\\ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\Webserver\\bin" + tempDir2 + "\\ReportObjects\\" + comboBox2.Text);
                copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件" + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement");

                MessageBox.Show("提取" + comboBox2.Text + "成功");
            }
            if (comboBox1.Text == "Batch Project")
            {
                copyDirectory(comboBox6.Text + tempDir + "\\BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件" + tempDir + "\\BatchObjects\\" + comboBox2.Text);
                copyDirectory(comboBox6.Text + tempDir1 + "\\BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件" + tempDir1 + "\\BatchObjects\\" + comboBox2.Text);
                copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件" + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement");

                MessageBox.Show("提取" + comboBox2.Text + "成功");
            }
            if (comboBox1.Text == "DataModel Project")
            {
                System.IO.File.Copy(comboBox6.Text + tempDir1 + "\\BusinessObjects\\DataModel\\DataModel." + comboBox2.Text + ".dcxml", textBox6.Text + "\\平台文件" + tempDir1 + "\\BusinessObjects\\DataModel\\DataModel." + comboBox2.Text + ".dcxml",true);
                MessageBox.Show("提取" + comboBox2.Text + "成功");
            }
        }

        #endregion

        #region 选项

        //提取文件路径设定按钮
        private void button61_Click(object sender, EventArgs e)  
        {
            folderBrowserDialog1.SelectedPath = textBox6.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox6.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button63_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox11.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox11.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button64_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox12.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox12.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button65_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox13.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox13.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button66_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox14.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox14.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button68_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox15.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox15.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button67_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox16.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox16.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button69_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox17.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox17.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button70_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox18.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox18.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button71_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox19.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox19.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button72_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox20.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox20.Text = folderBrowserDialog1.SelectedPath;
            }

        }

        private void button73_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox21.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox21.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button74_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox22.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox22.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button75_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox23.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox23.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button76_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox24.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox24.Text = folderBrowserDialog1.SelectedPath;
            }

        }

        private void button77_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox25.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox25.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button79_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "directory_File", textBox6.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File1", textBox11.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File2", textBox12.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File3", textBox13.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File4", textBox14.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File5", textBox15.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File6", textBox16.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File7", textBox17.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File8", textBox18.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File9", textBox19.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File10", textBox20.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File11", textBox21.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File12", textBox22.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File13", textBox23.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File14", textBox24.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "directory_File15", textBox25.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "ServerIP", textBox30.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "ServerPort", textBox31.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "CM_PWD", textBox32.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "111_PWD", textBox34.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "11_PWD", textBox35.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "HJDZ_PWD", textBox36.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "ALEX_PWD", textBox37.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "SEC", textBox33.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "Site", textBox38.Text, str); 		//修改INI文件中服务器节点的内容
                WritePrivateProfileString(strOne, "Programm", textBox39.Text, str); 		//修改INI文件中服务器节点的内容
                if (textBox33.Text != "")
                {
                    _SEC = Convert.ToInt32(textBox33.Text) * 1000;
                }
                MessageBox.Show("保存成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (textBox33.Text != "")
            {
                _SEC = Convert.ToInt32(textBox33.Text) * 1000;
            }
        }

        #endregion

        #region 单只编译查询、提取

        //单只编译查询、提取

        String r = "";
        private void panduan(object sender, EventArgs e)
        {
            if (r == comboBoxproduct2.Text)
            {
                return;
            }
            else 
            {
                Dir2_Load(sender, e);
                r = comboBoxproduct2.Text;
            }
        }
        private void Dir2_Load(object sender, EventArgs e)
        {
                comboBox10.Items.Clear();
                DirectoryInfo dinfo = null;

                if (comboBoxproduct2.Text == "E10_2.0")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_2.0");
                }
                if (comboBoxproduct2.Text == "E10_1.1.1")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_1.1.1");
                }
                if (comboBoxproduct2.Text == "DS_1.0")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\DS_1.0");
                }
                if (comboBoxproduct2.Text == "CM_1.1")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\CM_1.1");
                }
                if (comboBoxproduct2.Text == "E10_ALEX111")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_ALEX111");
                }
                if (comboBoxproduct2.Text == "E10_HJDZ111")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_HJDZ111");
                }
                if (comboBoxproduct2.Text == "E10_NBXL111")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_NBXL111");
                }
                if (comboBoxproduct2.Text == "E10_QTDG111")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_QTDG111");
                }
                if (comboBoxproduct2.Text == "E10_TCV111")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_TCV111");
                }
                if (comboBoxproduct2.Text == "E10_WJBZ111")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_WJBZ111");
                }
                if (comboBoxproduct2.Text == "E10_BAKE20")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_BAKE20");
                }
                if (comboBoxproduct2.Text == "E10_1.1.1_B")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\E10_1.1.1_B");
                }
                if (comboBoxproduct2.Text == "SRMS_2.0")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\SRMS_2.0");
                }
                if (comboBoxproduct2.Text == "SRMS_BAKE20")
                {
                    dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\SRMS_BAKE20");
                }

                //获取指定目录下的所有子目录及文件类型
                FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    //if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    //{
                    //    //使用获取的文件夹名称实例化DirectoryInfo对象
                    //    //DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                    //    //为ListView控件添加文件夹信息
                        comboBox10.Items.Add(fsinfo.Name);

                //    }
                //    else
                //    {
                //        //使用获取的文件夹名称实例化FileInfo对象
                //       // FileInfo dirinfo = new FileInfo(fsinfo.FullName);
                //        //为ListView控件添加文件夹信息
                //        //comboBox10.Items.Add(dirinfo.Name);

                //    }

                }
                //comboBox10.Text = comboBox10.Items[0].ToString();
            
        }

        private void button62_Click(object sender, EventArgs e)
        {
            string dirE10_1 = "", dirE10_2, dirE10_3;
            if (comboBoxproduct2.Text == "E10_2.0")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_2.0\\";
            }
            if (comboBoxproduct2.Text == "E10_1.1.1")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_1.1.1\\";
            }
            if (comboBoxproduct2.Text == "DS_1.0")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\DS_1.0\\";
            }
            if (comboBoxproduct2.Text == "CM_1.1")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\CM_1.1\\";
            }
            if (comboBoxproduct2.Text == "E10_ALEX111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_ALEX111\\";
            }
            if (comboBoxproduct2.Text == "E10_HJDZ111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_HJDZ11\\";
            }
            if (comboBoxproduct2.Text == "E10_NBXL111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_NBXL111\\";
            }
            if (comboBoxproduct2.Text == "E10_QTDG111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_QTDG111\\";
            }
            if (comboBoxproduct2.Text == "E10_TCV111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_TCV111\\";
            }
            if (comboBoxproduct2.Text == "E10_WJBZ111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_WJBZ111\\";
            }
            if (comboBoxproduct2.Text == "E10_BAKE20")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_BAKE20\\";
            }
            if (comboBoxproduct2.Text == "E10_1.1.1_B")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_1.1.1_B\\";
            }
            if (comboBoxproduct2.Text == "SRMS_2.0")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\SRMS_2.0\\";
            }
            if (comboBoxproduct2.Text == "SRMS_BAKE20")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\SRMS_BAKE20\\";
            }
            if (checkBox5.Checked)
            {
                dirE10_2 = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                copyDirectory(dirE10_1 + comboBox10.Text, dirE10_2 + "\\" + comboBox10.Text);
                MessageBox.Show("成功提取" + comboBox10.Text + "到桌面");
            }
            if (checkBox6.Checked)
            {
                dirE10_3 = comboBox6.Text;
                copyDirectory(dirE10_1 + comboBox10.Text, dirE10_3);
                MessageBox.Show("成功提取" + comboBox10.Text + "到平台");
            }

        }

        private void button2_Click(object sender, EventArgs e)   //刷新
        {
            Dir2_Load(sender, e);
        }
        #endregion
        
        #region 托盘

        //程序最小化
        //private void size_Changed(object sender, EventArgs e)
        //{
        //    if (this.WindowState == FormWindowState.Minimized) //判断是否最小化
        //    {
        //        this.ShowInTaskbar = true; //显示在系统任务栏
               
        //    }
        //}
       
        //当用户点击窗体右上角X按钮或(Alt + F4)时
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //HotKey.UnregisterHotKey(Handle, 100);
            if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生
            {
                e.Cancel = true;
                //this.ShowInTaskbar = false;
                //this.notifyIcon1.Visible = true;
                notifyIcon1.BalloonTipTitle = "程序已最小化";
                notifyIcon1.BalloonTipText = "程序还在继续运行......" + "\r\n" + "双击托盘图标还原窗口.";
                notifyIcon1.ShowBalloonTip(2000);
                this.Visible= false;

            }
        }

        //双击还原窗体
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            //if (this.WindowState == FormWindowState.Minimized)
            //{
            //    this.ShowInTaskbar = true; //显示在系统任务栏
            //    this.WindowState = FormWindowState.Normal; //还原窗体
            //    notifyIcon1.Visible = false; //托盘图标隐藏
            //}
            if (this.Visible == false)
            {
                this.Visible = true;
                this.Activate();
                this.Focus();                
            }
        }

        //实现重新显示窗体
        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.Visible == false)
            {
                this.Visible = true;
                this.Activate();
                this.Focus();
            }
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (client != null)
            {

                if (client.Client.Connected)
                {
                    AsyncSendMessage("Logout," + textBoxUserName.Text);
                    br.Close();
                    bw.Close();
                }
                isExit = true;
                client.Close();
            }

            Application.Exit();

        }

        #endregion

        #region 自动登录
        //自动登录
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr GetForegroundWindow();   //WINAPI 获取当前活动窗体的句柄

        [DllImport("User32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);

        const int WM_KEYDOWN = 0x0100;//按键按下
        const int WM_KEYUP = 0x0101;//按键放开
        const int WM_SETTEXT = 0x000C;//发送文本
        const int WM_CLICK = 0x00F5;//鼠标点击
        const int WM_SETFOCUS = 0x0007;//设置焦点参数

        public void login(String user,String password)
        {
            if (checkBox9.Checked == true)
            {
                string _user = user;
                string _password = password;
                IntPtr hWnd1 = FindWindow(null, "登录");                         //  
                SetForegroundWindow(hWnd1);
                //MessageBox.Show(GetForegroundWindow().ToString("X"));
                IntPtr hWnd2 = FindWindowEx(hWnd1, IntPtr.Zero, null, null);

                IntPtr hWnd3 = FindWindowEx(hWnd2, IntPtr.Zero, null, "常规");       // 
                //MessageBox.Show(hWnd2.ToString("X"));

                IntPtr hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.bf7771", null); // 
                //MessageBox.Show(hWnd31.ToString("X"));
                IntPtr hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.bf7771", null);      // 
                //MessageBox.Show(hWnd32.ToString("X"));
                if ((int)hWnd32 == 0)
                {
                    hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3d893c", null); // 
                    //MessageBox.Show(hWnd31.ToString("X"));
                    hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3d893c", null);      // 
                    //MessageBox.Show(hWnd32.ToString("X"));
                }
                if ((int)hWnd32 == 0)
                {
                    hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2004eee", null); // 
                    //MessageBox.Show(hWnd31.ToString("X"));
                    hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2004eee", null);      // 
                    //MessageBox.Show(hWnd32.ToString("X"));
                }
                if ((int)hWnd32 == 0)
                {
                    hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.21af1a5", null); // 
                    //MessageBox.Show(hWnd31.ToString("X"));
                    hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.21af1a5", null);      // 
                    //MessageBox.Show(hWnd32.ToString("X"));
                }


                //IntPtr hWnd3A = FindWindowEx(hWnd2, IntPtr.Zero, "AliEdit", null);        // 
                //IntPtr hWnd3B = FindWindowEx(hWnd3A, IntPtr.Zero, "ATL:03B9F4A8", null);  // 
                //IntPtr hWnd3C = FindWindowEx(hWnd3B, IntPtr.Zero, "ATL:Edit", null);      // 
                //MessageBox.Show(hWnd33.ToString("X"));

                SendMessage(hWnd31, WM_SETTEXT, (IntPtr)0, _user);
                SendMessage(hWnd32, WM_SETTEXT, (IntPtr)0, _password);

                IntPtr hWnd4 = FindWindowEx(hWnd3, IntPtr.Zero, null, "登 录"); // 
                //MessageBox.Show(hWnd4.ToString("X"));

                SetForegroundWindow(hWnd4);
                SendKeys.Send("{ENTER}");
            }
            else
            {
                return;
            }
        }

        private void radioButton13_Click(object sender, EventArgs e)
        {
            _PWD = textBox34.Text;
        }

        private void radioButton14_Click(object sender, EventArgs e)
        {
            _PWD = textBox35.Text;
        }

        private void radioButton15_Click(object sender, EventArgs e)
        {
            _PWD = textBox36.Text;
        }

        private void radioButton16_Click(object sender, EventArgs e)
        {
            _PWD = textBox37.Text;
        }

        private void checkBox9_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox9.Checked == true)
            {
                radioButton13.Enabled = true;
                radioButton14.Enabled = true;
                radioButton15.Enabled = true;
                radioButton16.Enabled = true;
                radioButton13.Checked = true;
            }
            else
            {
                radioButton13.Checked = false;
                radioButton14.Checked = false;
                radioButton15.Checked = false;
                radioButton16.Checked = false;
                radioButton13.Enabled = false;
                radioButton14.Enabled = false;
                radioButton15.Enabled = false;
                radioButton16.Enabled = false;
            }
        }
        #endregion

        #region 数据库

        #region 定义全局变量
        private static string strServer = "";  //SQL服务器
        private static string strUID = "";     //登录用户
        private static string strPwd = "";     //登录密码
        private static string strDatabase = "";//要执行操作的数据库名
        #endregion

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            strDatabase = e.Node.Text;
            if (strDatabase.Contains("服务器："))
            {
                button21.Enabled = button32.Enabled = button34.Enabled = button78.Enabled = false;
            }
            else
            {
                button21.Enabled = button32.Enabled = button34.Enabled = button78.Enabled = true;
                label37.Text = "你选择的是" + strDatabase + "数据库";
            }
        }

        private void toolStripTextBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                toolStripTextBox3.Focus();
        }

        private void toolStripTextBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                toolStripButton1_Click(sender, e);
        }

        //登录SQL服务器
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
             if (System.IO.File.Exists(str))											//判断是否存在INI文件
            {
                WritePrivateProfileString(strOne, "DatebaseServer", toolStripTextBox1.Text, str);
                WritePrivateProfileString(strOne, "Pwd", toolStripTextBox3.Text, str); 		//修改INI文件中服务器节点的内容

            }
            else
            {
                MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            
            treeView1.Nodes.Clear();
            try
            {
                strServer = toolStripTextBox1.Text;
                strUID = toolStripTextBox2.Text;
                strPwd = toolStripTextBox3.Text;
                string str1 = "Data Source=" + strServer + ";database=master;Uid=" + strUID + ";Pwd=" + strPwd + ";";
                TreeNode TNode = new TreeNode("服务器：" + strServer);
                DataTable myTable = getTable(str1, "select name from sysdatabases", "sysdatabases");
                for (int i = 0; i < myTable.Rows.Count; i++)
                    TNode.Nodes.Add(myTable.Rows[i]["name"].ToString());
                treeView1.Nodes.Add(TNode);
            }
            catch { }
        }

        //断开连接
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            con.Close();
            
            label3.Text = "数据库【" + textBox4.Text.Trim() + "】已经断开";
        }
        //选择备份文件的存放路径
        private void button32_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                textBox27.Text = folderBrowserDialog1.SelectedPath;
        }

        //备份数据库
        private void button21_Click(object sender, EventArgs e)
        {
            string filepath = "";
            if (textBox27.Text.EndsWith("\\"))
                filepath = textBox27.Text + textBox26.Text.Trim()+".bak";
            else
                filepath = textBox27.Text + "\\" + textBox26.Text.Trim()+".bak";
            if (!System.IO.File.Exists(filepath))
            {
                con = new SqlConnection();		//利用代码实现连接数据库
                con.ConnectionString = "Data Source=" + strServer + ";Database=" + strDatabase + ";uid=" + strUID + ";pwd=" + strPwd + ";";
                con.Open();
                SqlCommand com = new SqlCommand();
                com.CommandText = "BACKUP DATABASE " + strDatabase + " TO DISK = '" + filepath + "'with COMPRESSION";  //@"backup database test to disk='D:\backup' with init";

                com.Connection = con;	//连接
                com.ExecuteNonQuery();	//执行
                con.Close();
                MessageBox.Show("数据库备份成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("请重新命名！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        //选择要还原的数据库文件
        private void button78_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.bak(备份文件)|*.bak|*.*(所有文件)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox28.Text = openFileDialog1.FileName;
            }
        }

        //还原数据库
        private void button34_Click(object sender, EventArgs e)
        {
            string path = textBox28.Text;//获得备份文件路径
            if (path != "" && strDatabase != "")
            {
                string SqlStr1 = "Data Source=" + strServer + ";Database=" + "master" + ";uid=" + strUID + ";pwd=" + strPwd + ";";
                string SqlStr2 = "use master restore database " + strDatabase + " from disk='" + path + "'";
                string SqlStr3 = "backup log " + strDatabase + " to disk='" + path + "' use master restore database " + strDatabase + " from disk='" + path + "'";
                string single1 = "alter database " + strDatabase + " set single_user with rollback immediate " + SqlStr2;
                string single2 = "alter database " + strDatabase + " set single_user with rollback immediate " + SqlStr3;
                using (SqlConnection con1 = new SqlConnection(SqlStr1))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandTimeout = 360;
                    cmd.Connection = con1;
                    con1.Open();
                    //KILL DataBase Process
                    cmd = new SqlCommand("SELECT spid FROM sysprocesses ,sysdatabases WHERE sysprocesses.dbid=sysdatabases.dbid AND sysdatabases.Name='" + strDatabase + "'", con1);
                     SqlDataReader dr;
                     dr = cmd.ExecuteReader();
                     ArrayList list = new ArrayList();
                     while(dr.Read())
                     {
                      list.Add(dr.GetInt16(0));
                     }
                     dr.Close();
                     for(int i = 0; i < list.Count; i++)
                     {
                      cmd = new SqlCommand(string.Format("KILL {0}", list[i]), con1);
                      cmd.ExecuteNonQuery();
                     }

                     SqlCommand cmdRT = new SqlCommand();
                     cmdRT.CommandType = CommandType.Text;
                     cmdRT.Connection = con1;
                     cmdRT.CommandText = @"restore database " + strDatabase + " from disk='" + path + "'with replace";

                     try
                     {
                      cmdRT.ExecuteNonQuery();
                      MessageBox.Show("Restore successed.");
                     }
                     catch(Exception ex)
                     {
                      MessageBox.Show(ex.Message);
                     }
                     finally
                     {
                      con1.Close();
                     }
                }
            }
        }

           // 获得数据表结构
        /// <summary>
        /// 获得数据表结构
        /// </summary>
        /// <param name="strCon">连接字符串</param>
        /// <param name="strSql">SQL语句</param>
        /// <param name="strTable">数据表名</param>
        /// <returns>DataTable类型</returns>
        private DataTable getTable(string strCon, string strSql, string strTable)
        {
            try
            {
                SqlConnection sqlcon = new SqlConnection(strCon);
                SqlDataAdapter da = new SqlDataAdapter(strSql, sqlcon);
                DataTable dt = new DataTable(strTable);
                da.Fill(dt);
                return dt;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 更新日志
        private void menuItem11_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.Show();
        }
        #endregion

        #region 快捷键
        protected override void WndProc(ref Message m)
        {
            
            switch (m.WParam.ToInt64())
            {
                case 100:
                    if (this.WindowState == FormWindowState.Minimized)
                    {
                        this.WindowState = FormWindowState.Normal;
                        this.Activate();
                        this.Focus();

                        //this.TopMost = true;
                        break;
                    }
                    if (this.Visible == false)
                    {
                        this.Visible = true;
                        //this.TopMost = true;
                        this.Activate();
                        this.Focus();

                    }
                    else if (this.Visible == true)
                    {
                        this.Visible = false;
                    }
                    break;
            }
            base.WndProc(ref m);
        }
        #endregion

        #region 记录目录到dir和读取目录
        private void WriteTxt(string S)
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamWriter w = new StreamWriter(Current + "\\dir.txt", true);
            w.WriteLine(S);
            w.Flush();
            w.Close();

        }
        private void ReadDir()
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamReader w = new StreamReader(Current + "\\dir.txt", true);
            string strLine = string.Empty;
            while ((strLine = w.ReadLine()) != null)
            {
                comboBox6.Items.Add(strLine);
            }
        }

        #endregion

        #region 订饭

        public void transferMenu(string menu)
        {
            if (menu == "")
            {
                AsyncSendMessage("Order," + Dns.GetHostName() + "," + "随便点");
            }
            else if (menu == "不订")
            {
                AsyncSendMessage("NoOrder," + Dns.GetHostName());
            }
            else
            {
                AsyncSendMessage("Order," + Dns.GetHostName() + "," + menu);
            }
        }

        #endregion

        #region 简单部署

        private void 更新到平台_Click(object sender, EventArgs e)
        {
            string mulu = "";
            if (comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
                comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
                comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
                comboBoxproduct1.Text != "SRMS_BAKE20")
            {
                mulu = "\\Customization";
            }
            DirectoryInfo dinfo = new DirectoryInfo(dir + comboBox2.Text);
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            if (comboBox1.Text == "Designer Project" || comboBox1.Text == "DataModel Project")
            {
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        if (!(fsinfo.Name.Equals("bin") || fsinfo.Name.Equals("TEMP") || fsinfo.Name.Equals("Client") || fsinfo.Name.Equals("Server")
                            || fsinfo.Name.Equals("ServiceSpec")))
                        {
                            dinfo = new DirectoryInfo(dir + comboBox2.Text + "\\" + fsinfo.Name);
                            FileSystemInfo[] fsinfos1 = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo1 in fsinfos1)
                            {
                                if (fsinfo1 is DirectoryInfo)    //判断是否文件夹
                                {

                                }
                                else
                                {
                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "CSDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "BDSdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "FDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "SWDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "GVDdcxml")
                                    {

                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        else
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);

                                        }


                                    }

                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                    }
                                    if (fsinfo1.FullName.Substring(
                               fsinfo1.FullName.LastIndexOf(".") + 1,
                               fsinfo1.FullName.Length -
                               fsinfo1.FullName.LastIndexOf(".") - 1) == "dcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[0] == "LayoutContainer" && sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        if (sp[0] == "LayoutContainer" && !sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "MRDdcxml" || fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "QPJdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "VDdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Client" + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                  fsinfo.FullName.LastIndexOf(".") + 1,
                  fsinfo.FullName.Length -
                  fsinfo.FullName.LastIndexOf(".") - 1) == "DMdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu + "\\BusinessObjects\\DataModel\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                        }
                    }
                }
                MessageBox.Show("已更新");
            }
            if (comboBox1.Text == "Batch Project")
            {
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        if (!(fsinfo.Name.Equals("bin") || fsinfo.Name.Equals("TEMP") || fsinfo.Name.Equals("Client") || fsinfo.Name.Equals("Server")
                            || fsinfo.Name.Equals("ServiceSpec")))
                        {
                            dinfo = new DirectoryInfo(dir + comboBox2.Text + "\\" + fsinfo.Name);
                            FileSystemInfo[] fsinfos1 = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo1 in fsinfos1)
                            {
                                if (fsinfo1 is DirectoryInfo)    //判断是否文件夹
                                {

                                }
                                else
                                {
                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "CSDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "BDSdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "FDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "SWDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "GVDdcxml")
                                    {

                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        else
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);

                                        }


                                    }

                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                    }
                                    if (fsinfo1.FullName.Substring(
                               fsinfo1.FullName.LastIndexOf(".") + 1,
                               fsinfo1.FullName.Length -
                               fsinfo1.FullName.LastIndexOf(".") - 1) == "dcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[0] == "LayoutContainer" && sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        if (sp[0] == "LayoutContainer" && !sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "MRDdcxml" || fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "QPJdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "VDdcxml"|| fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "BAHdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Client" + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                  fsinfo.FullName.LastIndexOf(".") + 1,
                  fsinfo.FullName.Length -
                  fsinfo.FullName.LastIndexOf(".") - 1) == "DMQdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu + "\\BatchObjects\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                        }
                    }
                }
                MessageBox.Show("已更新");
            }
            if (comboBox1.Text == "Report Project")
            {

            }
        }

        #endregion

        #region 更改IIS物理路径

        private void comboBox6_SelectedValueChanged(object sender, EventArgs e)
        {
            WritePrivateProfileString(strOne, "Data Source", comboBox6.Text, str);
            //Process.Start("c:\\windows\\system32\\inetsrv\\appcmd.exe", "set app /app.name: " + "\"" + textBox38.Text + "/" + textBox39.Text + "\"" + " /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\" + textBox39.Text + "\"");
            string cmd = "c:\\windows\\system32\\inetsrv\\appcmd.exe set app /app.name: " + "\"" + textBox38.Text + "/" + textBox39.Text + "\"" + " /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\WebServer" + "\"";
            //Console.WriteLine(Execute(cmd, 0).ToString());
            Execute(cmd, 0);
        }

        public static string Execute(string dosCommand, int outtime)
        {
            string output = "";
            if (dosCommand != null && dosCommand != "")
            {
                System.Diagnostics.Process process = new Process();//创建进程对象
                System.Diagnostics.ProcessStartInfo startinfo = new ProcessStartInfo();//创建进程时使用的一组值，如下面的属性
                startinfo.FileName = "cmd.exe";//设定需要执行的命令程序
                //以下是隐藏cmd窗口的方法
                startinfo.Arguments = "/c" + dosCommand;//设定参数，要输入到命令程序的字符，其中"/c"表示执行完命令后马上退出
                startinfo.UseShellExecute = false;      //不使用系统外壳程序启动
                startinfo.RedirectStandardInput = false;//不重定向输入
                startinfo.RedirectStandardOutput = true;//重定向输出，而不是默认的显示在dos控制台上
                startinfo.CreateNoWindow = true;        //不创建窗口
                process.StartInfo = startinfo;
                try
                {
                    if (process.Start())        //开始进程
                    {
                        if (outtime == 0)
                        {
                            process.WaitForExit();
                        }
                        else
                        {
                            process.WaitForExit(outtime);
                        }
                        output = process.StandardOutput.ReadToEnd();//读取进程的输出
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                finally
                {
                    if (process != null)
                    {
                        process.Close();
                    }
                }
            }
            return output;
        }

        #endregion

        #region 记录目录到dir和读取目录
        private void WriteProduct(string S)
        {
            bool flag = false;
            foreach (object list in comboBoxproduct.Items)
            {
                if (S.Equals(list))
                {
                    flag = true;
                }
            }

            if (!flag)
            {
                var Current = Directory.GetCurrentDirectory();//获取当前根目录
                //true是追加方式，false是覆盖方式
                StreamWriter w = new StreamWriter(Current + "\\product.txt", true);
                w.WriteLine(S);
                w.Flush();
                w.Close();
            }
        }
        private void ReadProduct(ComboBox combox)
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamReader w = new StreamReader(Current + "\\product.txt", true);
            string strLine = string.Empty;
            while ((strLine = w.ReadLine()) != null)
            {
                bool flag = false;
                foreach (object list in combox.Items)
                {
                    if (strLine.Equals(list))
                    {
                        flag = true;
                    }
                }

                if (!flag)
                {
                    combox.Items.Add(strLine);
                }             
            }
            w.Close();
        }
        #endregion

       

       
    }
}


 
